package LC;

/**
 * @ClassName LC33
 * @Description: TODO
 * @Author hl
 * @Date 2020/6/11
 * @Version V1.0
 **/
public class LC33 {

    public int search(int[] nums, int target) {
        if(nums==null||nums.length==0){
            return  -1;
        }
        int low=0;
        int high=nums.length-1;
        while(low<=high){
            int mid=(low+high)/2;
            if(nums[mid]==target){
                return mid;
            }

            if(nums[low]<=nums[mid]){
                if(target>=nums[low]&&target<nums[mid]){
                    high=mid-1;
                }else{
                    low=mid+1;
                }
            }

            if(nums[mid]<=nums[high]){
                if(target>nums[mid]&&target<=nums[high]){
                     low=mid+1;
                }else{
                    high=mid-1;
                }
            }
        }
        return  -1;
    }
}
